<template>
  <page-container>
    <search-form
      v-model="searchForm"
      :searchColumns="searchColumns"
      :searchOptions="{ menuSpan: 8 }"
      @on-search="handleSearch">
      <template v-slot:newBtn>
        <el-button
          type="primary"
          @click="handelAddForm()"
          >新增国家黑名单</el-button
        >
      </template>
    </search-form>

    <avue-table
      :dataList="dataList"
      :loading="loading"
      :page="page"
      :tableColumns="tableColumns"
      @onPageChange="onPageChange">
      <template v-slot:menu="{ row }">
        <el-button
          type="danger"
          icon="el-icon-delete"
          @click="delRow(row.id)"
          circle></el-button>
      </template>
    </avue-table>
  </page-container>
</template>

<script>
import tableMixins from '@/mixins/table'
import { deepClone } from '@/utils'
import { mapGetters } from 'vuex'
import { queryBlackList, addBlackform, delBlackform } from '@/api/userManage'
import { searchColumns, tableColumns, addDialogForm } from './config/table-config'

export default {
  mixins: [tableMixins],
  data() {
    return {
      searchForm: {},
    }
  },
  computed: {
    ...mapGetters(['commonData', 'countryList']),
    userList() {
      return this.commonData?.userList ?? []
    },
    addDialogForm,
    searchColumns,
    tableColumns,
  },
  methods: {
    fetchMethod: queryBlackList,
    delMethod: delBlackform,
    // 查询参数格式化
    formatSearch() {
      const searchParams = deepClone(this.searchForm)
      return searchParams
    },
    handelAddForm() {
      this.$dialogForm.show({
        width: '30%',
        title: '新增国家黑名单',
        option: {
          column: this.addDialogForm,
        },
        callback: async ({ data, close }) => {
          const parms = {
            country_name: this.countryList?.find(item => item.id === data?.country_name)?.full_name,
            country_id: data?.country_name,
          }
          const resData = await addBlackform(parms)
          if (resData.code === 0) {
            this.$message.success('新增成功')
          }
          this.getList()
          close()
        },
      })
    },
  },
  mounted() {
    this.handleSearch()
  },
}
</script>

<style lang="scss" scoped></style>
